package com.zyy.smartcity1129.util;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public abstract class RvAd<T> extends RecyclerView.Adapter<RvAd.VH> {
    private final List<T> tl;
    private final int layId;

    public RvAd(List<T> tl, int layId) {
        this.tl = tl;
        this.layId = layId;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new VH(LayoutInflater.from(parent.getContext()).inflate(layId,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        initR(holder.itemView,tl.get(position),position);
    }

    @Override
    public int getItemCount() {
        return tl.size();
    }

    protected abstract void initR(View vi,T t,int p);

    static class VH extends RecyclerView.ViewHolder{

        public VH(@NonNull View itemView) {
            super(itemView);
        }
    }
}
